#include <WinSock2.h>
#include <MSWSock.h>
#include <DbgHelp.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
extern "C"
{
#include "skynet.h"
#include "skynet_imp.h"
#include "skynet_env.h"
#include "skynet_server.h"
}

#pragma comment(lib,"wsock32.lib")
#pragma comment(lib,"dbghelp.lib")
#pragma comment(lib,"../3rd/lib/pthread_lib.lib")
#pragma comment(lib,"../3rd/lib/lualib.lib")


void createDumpFile(PEXCEPTION_POINTERS pException)
{
	MINIDUMP_EXCEPTION_INFORMATION info;
	info.ThreadId = GetCurrentThreadId();
	info.ExceptionPointers = pException;
	info.ClientPointers = 0;
	CHAR path[MAX_PATH];
	GetModuleFileName(NULL,path,sizeof(path));
	lstrcpy(path + lstrlen(path) - 5,".dump");
	HANDLE hFile = CreateFile(path,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
	MiniDumpWriteDump(GetCurrentProcess(),GetCurrentProcessId(),hFile,MiniDumpNormal,(pException) ? &info:NULL,NULL,NULL);
	CloseHandle(hFile);

}

long __stdcall DumpExceptionFilter(PEXCEPTION_POINTERS pException)
{
	createDumpFile(pException);
	return EXCEPTION_EXECUTE_HANDLER;
}



int main(int argc,char* argv[])
{
	::SetUnhandledExceptionFilter(DumpExceptionFilter);
	skynet_globalinit();
	skynet_env_init();
	void* a = NULL;
	int b = *(int*)(a);
	printf("%d\n", b);
	::SetUnhandledExceptionFilter(DumpExceptionFilter);
}